package com.jsb.laundry.service;

import com.jsb.laundry.common.config.Constant;
import com.jsb.laundry.common.utils.JSBUtil;
import com.jsb.laundry.model.entity.BusinessType;
import com.jsb.laundry.model.entity.CapitalAccount;
import com.jsb.laundry.model.entity.CapitalAccountUnstLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderSplittingServiceImpl {

    private static final Logger LOGGER = LoggerFactory.getLogger(OrderSplittingServiceImpl.class);
    @Resource
    private ServeService serveService;


    /**
     * 代理分佣
     *
     * @param orderId    订单id
     * @param riderId    骑手id
     * @param ledgerType 分佣类型
     * @return
     */
    @Transactional
    public void agencyCommission(String orderId, String riderId, String ledgerType) {
        //查询订单金额
        int money = serveService.findByOrderMoney(orderId);//用户实际消费金额
        double ledgerMoney = Constant.rider_commission * money;//分佣金额
        if ("1".equals(ledgerType)) {//待结算
            //待结算更新
            riderAgencyCommission(orderId, riderId, (int) ledgerMoney);//包括系统出账加日志
//            splitSettled(orderId);//已经结算
        } else if ("2".equals(ledgerType)) {//已结算
            //系统账户支出
            CapitalAccount systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
            //判断 资金账户不能未null
            if (systemAccountInfo == null) {
                LOGGER.info("OrderSplittingServiceImpl:agencyCommission, systemAccount is null, orderId:{}, riderId:{}, ledgerType:{}", orderId, riderId, ledgerType);
                return;
            }
            //1 系统账户可提现扣除
            int sysAccountAddDepositResult = serveService.updateDepositSub((int) ledgerMoney, systemAccountInfo.getId());//扣除可提现
            if (sysAccountAddDepositResult == 0) {
                LOGGER.info("OrderSplittingServiceImpl:agencyCommission, sysAccount updateDepositSub failed, orderId:{}, riderId:{}, ledgerType:{}, systemAccountInfo:{}",
                        orderId, riderId, ledgerType, systemAccountInfo);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }
            //2 系统账户已结算加日志
            systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
            int sysAccountAddLogResult = instertAccountLog(systemAccountInfo.getId(), "out", "客户下单分佣" + "单号:" + orderId, orderId, (int) ledgerMoney,
                    BusinessType.ledger_rewards, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                    (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                    systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
            if (sysAccountAddLogResult == 0) {
                LOGGER.info("OrderSplittingServiceImpl:agencyCommission, updateDepositSub failed, orderId:{}, riderId:{}, ledgerType:{}, systemAccountInfo:{}",
                        orderId, riderId, ledgerType, systemAccountInfo);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }
            //3 上级增加佣金
            CapitalAccount riderAccountInfo = serveService.capitalAccountInfo(riderId, "2");
            //骑手账户支出
            int riderAccountAddDepositResult = serveService.updateDepositAdd((int) ledgerMoney, riderAccountInfo.getId());//增加可提现金额
            if (riderAccountAddDepositResult == 0) {
                LOGGER.info("OrderSplittingServiceImpl:agencyCommission, riderAccount updateDepositSub failed, orderId:{}, riderId:{}, ledgerType:{}, systemAccountInfo:{}, riderAccountInfo:{}",
                        orderId, riderId, ledgerType, systemAccountInfo, riderAccountInfo);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }
            //4 上级增加佣金已结算记录
            riderAccountInfo = serveService.capitalAccountInfo(riderId, "2");
            int riderAccountAddLogResult = instertAccountLog(riderAccountInfo.getId(), "in", "客户下单分佣" + "单号:" + orderId, orderId, (int) ledgerMoney,
                    BusinessType.ledger_rewards, (int) riderAccountInfo.getDeposit(), (int) riderAccountInfo.getDepositFreeze(),
                    (int) riderAccountInfo.getWithdraw(), (int) riderAccountInfo.getWithdrawFreeze(),
                    riderAccountInfo.getScore(), (int) riderAccountInfo.getAccountAmount());
            if (riderAccountAddLogResult == 0) {
                LOGGER.info("OrderSplittingServiceImpl:agencyCommission, riderAccount instertAccountLog failed, orderId:{}, riderId:{}, ledgerType:{}, systemAccountInfo:{}, riderAccountInfo:{}",
                        orderId, riderId, ledgerType, systemAccountInfo, riderAccountInfo);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
        }
    }

    /**
     * 用户下单-上级代理分佣
     *
     * @param payId
     * @param thirdpartId
     * @param amount
     */
    @Transactional
    public void riderAgencyCommission(String payId, String thirdpartId, int amount) {
        //系统账户支出
        CapitalAccount systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        //判断 资金账户不能未null
        if (systemAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:riderAgencyCommission, systemAccount is null, payId:{}, thirdpartId{}, amount:{}", payId, 5, amount);
            return;
        }

        //系统账户出金-骑手返佣待结算扣减
        int sysAccountDepositFreezeSubResult = serveService.updatedepositfreezesub(amount, systemAccountInfo.getId());
        if (sysAccountDepositFreezeSubResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:riderAgencyCommission, systemAccount updatedepositfreezesub failed, payId:{}, thirdpartId:{}, amount:{}, systemAccountInfo:{}",
                    payId, 5, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //系统账户出金-骑手返佣待结算记录增加
        systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        int sysAccountAddUnstlogResult = instertAccountUnstlog(systemAccountInfo.getId(), "out", "客户下单分佣:" + payId, payId, amount,
                BusinessType.ledger_rewards, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (sysAccountAddUnstlogResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:riderAgencyCommission, systemAccount instertAccountUnstlog failed, payId:{}, thirdpartId:{}, amount:{}, systemAccountInfo:{}, ",
                    payId, 5, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }

        //查询骑手资金账户信息
        CapitalAccount riderAccountInfo = serveService.capitalAccountInfo(thirdpartId, "2");
        //判断 资金账户不能未null
        if (riderAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:riderAgencyCommission, riderAccountInfo is null, payId:{}, thirdpartId{}, amount:{}", payId, thirdpartId, amount);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //骑手账户待结算增加返佣金额
        int riderAccount = serveService.updatedepositfreezeadd(amount, riderAccountInfo.getId());
        if (riderAccount == 0) {
            LOGGER.info("OrderSplittingServiceImpl:riderAgencyCommission, riderAccountInfo updatedepositfreezeadd failed, payId:{}, thirdpartId{}, amount:{}, riderAccountInfo:{}", payId, thirdpartId, amount, riderAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //骑手账户待结算增加日志
        riderAccountInfo = serveService.capitalAccountInfo(thirdpartId, "2");
        int riderSplittingIn = instertAccountUnstlog(riderAccountInfo.getId(), "in", "客户下单分佣:" + payId, payId, amount,
                BusinessType.ledger_rewards, (int) riderAccountInfo.getDeposit(), (int) riderAccountInfo.getDepositFreeze(),
                (int) riderAccountInfo.getWithdraw(), (int) riderAccountInfo.getWithdrawFreeze(),
                riderAccountInfo.getScore(), (int) riderAccountInfo.getAccountAmount());
        if (riderSplittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:riderAgencyCommission, riderAccountInfo instertAccountUnstlog failed, payId:{}, thirdpartId{}, amount:{}, riderAccountInfo:{}", payId, thirdpartId, amount, riderAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }

    /**
     * 新增待结算记录
     *
     * @param accountId
     * @param type
     * @param remark
     * @param relatedNo
     * @param amount
     * @param businessType
     * @param deposit
     * @param depositFreeze
     * @param withdraw
     * @param withdrawFreeze
     * @param score
     * @param accountAmount
     */
    public int instertAccountUnstlog(
            String accountId,
            String type,
            String remark,
            String relatedNo,
            int amount,
            String businessType,
            int deposit,
            int depositFreeze,
            int withdraw,
            int withdrawFreeze,
            String score,
            int accountAmount
    ) {

        CapitalAccountUnstLog capitalAccountUnstLog = new CapitalAccountUnstLog();
        String uuid = JSBUtil.generateUUID();
        capitalAccountUnstLog.setSerialNum(uuid);//流水号
        capitalAccountUnstLog.setAccountId(accountId);//账号id（capital_account表里的id）
        capitalAccountUnstLog.setType(type);//类型
        capitalAccountUnstLog.setRemark(remark);//备注
        capitalAccountUnstLog.setRelatedNo(relatedNo);//关联订单号
        capitalAccountUnstLog.setAmount(amount);//发生金额
        capitalAccountUnstLog.setBusinessType(businessType);//业务类型
        capitalAccountUnstLog.setDeposit(deposit);//可提现金额
        capitalAccountUnstLog.setDepositFreeze(depositFreeze);//待结算金额
        capitalAccountUnstLog.setWithdraw(withdraw);//提现金额
        capitalAccountUnstLog.setWithdrawFreeze(withdrawFreeze);//提现中金额
        capitalAccountUnstLog.setScore(score);//积分
        capitalAccountUnstLog.setAccountAmount(accountAmount);//账户余额
        int addResult = serveService.addCapitalAccountUnstLog(capitalAccountUnstLog);
        if (addResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:instertAccountUnstlog, instert failed, capitalAccountLog:{}", capitalAccountUnstLog);
        }
        return addResult;
    }

    /**
     * 新增已结算记录
     *
     * @param accountId
     * @param type
     * @param remark
     * @param relatedNo
     * @param amount
     * @param businessType
     * @param deposit
     * @param depositFreeze
     * @param withdraw
     * @param withdrawFreeze
     * @param score
     * @param accountAmount
     */
    public int instertAccountLog(
            String accountId,
            String type,
            String remark,
            String relatedNo,
            int amount,
            String businessType,
            int deposit,
            int depositFreeze,
            int withdraw,
            int withdrawFreeze,
            String score,
            int accountAmount
    ) {

        CapitalAccountUnstLog capitalAccountLog = new CapitalAccountUnstLog();
        String uuid = JSBUtil.generateUUID();
        capitalAccountLog.setSerialNum(uuid);//流水号
        capitalAccountLog.setAccountId(accountId);//账号id（capital_account表里的id）
        capitalAccountLog.setType(type);//类型
        capitalAccountLog.setRemark(remark);//备注
        capitalAccountLog.setRelatedNo(relatedNo);//关联订单号
        capitalAccountLog.setAmount(amount);//发生金额
        capitalAccountLog.setBusinessType(businessType);//业务类型
        capitalAccountLog.setDeposit(deposit);//可提现金额
        capitalAccountLog.setDepositFreeze(depositFreeze);//待结算金额
        capitalAccountLog.setWithdraw(withdraw);//提现金额
        capitalAccountLog.setWithdrawFreeze(withdrawFreeze);//提现中金额
        capitalAccountLog.setScore(score);//积分
        capitalAccountLog.setAccountAmount(accountAmount);//账户余额
        int addResult = serveService.capitalAccountLogadd(capitalAccountLog);
        if (addResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:instertAccountLog, instert failed, capitalAccountLog:{}", capitalAccountLog);
        }
        return addResult;
    }


    /**
     * 资金业务处理 订单支付分账给公司
     *
     * @param payId  支付单号
     * @param amount 订单金额
     */
    @Transactional
    public void OrderPaySplitting(String payId, int amount) {
        String sysThirdpartId = "jsb";

        //查询本账户的资金信息
        CapitalAccount systemAccountInfo = serveService.capitalAccountInfo(sysThirdpartId, "5");
        //判断 资金账户不能未null
        if (systemAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:OrderPaySplitting, systemAccount is null, payId:{}, amount:{}", payId, amount);
            return;
        }

        //1 系统账户待结算增加支付金额
        int sysAccountDpositFreezeAddResult = serveService.updatedepositfreezeadd(amount, systemAccountInfo.getId());
        if (sysAccountDpositFreezeAddResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderPaySplitting, systemAccount updatedepositfreezeadd failed, payId:{}, amount:{}, systemAccountInfo:{}",
                    payId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //2 系统账户增加支付金额 add unstLog
        systemAccountInfo = serveService.capitalAccountInfo(sysThirdpartId, "5");
        int sysAccountAddUnstlogResult = instertAccountUnstlog(systemAccountInfo.getId(), "in", "订单支付:" + payId, payId, amount,
                BusinessType.order_paid, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (sysAccountAddUnstlogResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderPaySplitting, order_paid instertAccountUnstlog failed, payId:{}, amount:{}, systemAccountInfo:{}",
                    payId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //支付手续费计算
        double gatewayFee = amount * Constant.pay_commission;
        //3 系统账户待结算扣除网关手续费
        int sysAccountDpositFreezeSubResult = serveService.updatedepositfreezesub((int) gatewayFee, systemAccountInfo.getId());
        if (sysAccountDpositFreezeSubResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderPaySplitting, systemAccount updatedepositfreezesub payCommission failed, payId:{}, amount:{}, payCommission{}, systemAccountInfo:{}",
                    payId, amount, gatewayFee, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //4 系统账户待结算扣除网关手续费 add unstLog
        systemAccountInfo = serveService.capitalAccountInfo(sysThirdpartId, "5");
        int splittingOut = instertAccountUnstlog(systemAccountInfo.getId(), "out", "支付网关手续费:" + payId, payId, (int) gatewayFee,
                BusinessType.gateway_fee, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (splittingOut == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderPaySplitting, gateway_fee instertAccountUnstlog failed, payId:{}, amount:{}, systemAccountInfo:{}",
                    payId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //5 网关账户增加支付网关手续费
        CapitalAccount gatewayAccountInfo = serveService.capitalAccountInfo("gateway", "6");
        int gatewayAccountResult = serveService.updatedepositfreezeadd((int) gatewayFee, gatewayAccountInfo.getId());
        if (gatewayAccountResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderPaySplitting, gatewayAccount updatedepositfreezeadd failed, payId:{}, amount:{}, systemAccountInfo:{}, gatewayAccountInfo:{}, gatewayFee:{}",
                    payId, amount, systemAccountInfo, gatewayAccountInfo, gatewayFee);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        gatewayAccountInfo = serveService.capitalAccountInfo("gateway", "6");
        //6 网关账户增加支付网关手续费 add unstLog
        int gatewaySplittingInResult = instertAccountUnstlog(gatewayAccountInfo.getId(), "in", "支付网关手续费:" + payId, payId, (int) gatewayFee,
                BusinessType.gateway_fee, (int) gatewayAccountInfo.getDeposit(), (int) gatewayAccountInfo.getDepositFreeze(),
                (int) gatewayAccountInfo.getWithdraw(), (int) gatewayAccountInfo.getWithdrawFreeze(),
                gatewayAccountInfo.getScore(), (int) gatewayAccountInfo.getAccountAmount());
        if (gatewaySplittingInResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderPaySplitting, order_paid gateway_fee instertAccountUnstlog failed, payId:{}, amount:{}, systemAccountInfo:{}, gatewayAccountInfo:{}, gatewayFee:{}",
                    payId, amount, systemAccountInfo, gatewayAccountInfo, gatewayFee);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }


    /**
     * 资金业务处理 用户充值记入已结算
     *
     * @param payId  支付单号
     * @param amount 订单金额
     */
    @Transactional
    public void OrderUserRecharge(String payId, int amount) {
        //查询本账户的资金信息
        CapitalAccount systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        //判断 资金账户不能未null
        if (systemAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, systemAccount is null, payId:{}, amount:{}", payId, amount);
            return;
        }

        //1 系统账户已结算增加支付金额
        int systemAccount = serveService.updateDepositAdd(amount, systemAccountInfo.getId());
        if (systemAccount == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, systemAccount updateDepositAdd failed, payId:{}, amount:{}, systemAccountInfo:{}",
                    payId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //2 系统账户增加支付金额 add Log
        systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        int splittingIn = instertAccountLog(systemAccountInfo.getId(), "in", "用户充值:" + payId, payId, amount,
                BusinessType.user_recharge, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (splittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, user_recharge instertAccountLog failed, payId:{}, amount:{}, systemAccountInfo:{}",
                    payId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        double gatewayFee = amount * Constant.pay_commission;

        //3 系统账户已结算扣除网关手续费
        int systemAccounts = serveService.updateDepositSub((int) gatewayFee, systemAccountInfo.getId());
        if (systemAccounts == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, systemAccount updateDepositSub failed, payId:{}, amount:{}, systemAccountInfo:{}",
                    payId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //4 系统账户已结算扣除网关手续费 add Log
        systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        int splittingOut = instertAccountLog(systemAccountInfo.getId(), "out", "支付网关手续费:" + payId, payId, (int) gatewayFee,
                BusinessType.gateway_fee, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (splittingOut == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, gateway_fee instertAccountLog failed, payId:{}, amount:{}, systemAccountInfo:{}",
                    payId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //5 网关账户增加支付网关手续费
        CapitalAccount gatewayAccountInfo = serveService.capitalAccountInfo("gateway", "6");
        if (gatewayAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, gatewayAccount is null, payId:{}, amount:{}, systemAccountInfo:{}",
                    payId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        int gatewayAccountResult = serveService.updateDepositAdd((int) gatewayFee, gatewayAccountInfo.getId());
        if (gatewayAccountResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, gatewayAccount updateDepositAdd failed, payId:{}, amount:{}, systemAccountInfo:{}, gatewayAccountInfo:{}, gatewayFee:{}",
                    payId, amount, systemAccountInfo, gatewayAccountInfo, gatewayFee);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        gatewayAccountInfo = serveService.capitalAccountInfo("gateway", "6");
        //6 网关账户增加支付网关手续费 add Log
        int gatewaySplittingInResult = instertAccountLog(gatewayAccountInfo.getId(), "in", "支付网关手续费:" + payId, payId, (int) gatewayFee,
                BusinessType.gateway_fee, (int) gatewayAccountInfo.getDeposit(), (int) gatewayAccountInfo.getDepositFreeze(),
                (int) gatewayAccountInfo.getWithdraw(), (int) gatewayAccountInfo.getWithdrawFreeze(),
                gatewayAccountInfo.getScore(), (int) gatewayAccountInfo.getAccountAmount());
        if (gatewaySplittingInResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, order_paid gateway_fee instertAccountLog failed, payId:{}, amount:{}, systemAccountInfo:{}, gatewayAccountInfo:{}, gatewayFee:{}",
                    payId, amount, systemAccountInfo, gatewayAccountInfo, gatewayFee);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }

    /**
     * 资金业务处理 订单分账；根据订单号查出分账记录，按各角色进行分账，把待结算划转到可提现
     *
     * @param payId 支付单号
     */
    @Transactional
    public void splitSettled(String payId) {
        //根据订单号查询待结算的列表
        List<CapitalAccountUnstLog> capitalAccountUnstLogList = serveService.findByCapitalAccountUnstLogList(payId);
        for (CapitalAccountUnstLog capitalAccountUnstLog : capitalAccountUnstLogList) {
            //更新已结算
            CapitalAccount capitalAccount = serveService.capitalAccountInfoForUpdate(capitalAccountUnstLog.getAccountId());
            if (capitalAccount == null) {
                LOGGER.info("OrderSplittingServiceImpl:splitSettled, capitalAccount is null, payId:{}, capitalAccountUnstLog:{}", payId, capitalAccountUnstLog);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }
            if ("in".equals(capitalAccountUnstLog.getType())) {
                int updateDepositAddResult = serveService.updateDepositAdd(capitalAccountUnstLog.getAmount(), capitalAccountUnstLog.getAccountId());
                if (updateDepositAddResult == 0) {
                    LOGGER.info("OrderSplittingServiceImpl:splitSettled, updateDepositAdd failed, payId:{}, capitalAccountUnstLog:{}", payId, capitalAccountUnstLog);
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return;
                }
                int updatedepositfreezesubResult = serveService.updatedepositfreezesub(capitalAccountUnstLog.getAmount(), capitalAccountUnstLog.getAccountId());
                if (updatedepositfreezesubResult == 0) {
                    LOGGER.info("OrderSplittingServiceImpl:splitSettled, updatedepositfreezesub failed, payId:{}, capitalAccountUnstLog:{}", payId, capitalAccountUnstLog);
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return;
                }
            } else if ("out".equals(capitalAccountUnstLog.getType())) {
                int updateDepositSubResult = serveService.updateDepositSub(capitalAccountUnstLog.getAmount(), capitalAccountUnstLog.getAccountId());
                if (updateDepositSubResult == 0) {
                    LOGGER.info("OrderSplittingServiceImpl:splitSettled, updateDepositSub failed, payId:{}, capitalAccountUnstLog:{}", payId, capitalAccountUnstLog);
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return;
                }
                int updatedepositfreezeaddResult = serveService.updatedepositfreezeadd(capitalAccountUnstLog.getAmount(), capitalAccountUnstLog.getAccountId());
                if (updatedepositfreezeaddResult == 0) {
                    LOGGER.info("OrderSplittingServiceImpl:splitSettled, updatedepositfreezeadd failed, payId:{}, capitalAccountUnstLog:{}", payId, capitalAccountUnstLog);
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return;
                }
            }
            //更新已结算的标识
            int updateIsSettResult = serveService.updateIsSett(payId, capitalAccountUnstLog.getId());
            if (updateIsSettResult == 0) {
                LOGGER.info("OrderSplittingServiceImpl:splitSettled, updateIsSett failed, payId:{}, capitalAccountUnstLog:{}", payId, capitalAccountUnstLog);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }
            //添加到已结算表
            capitalAccount = serveService.capitalAccountInfoForUpdate(capitalAccountUnstLog.getAccountId());
            capitalAccountUnstLog.setAccountAmount((int) capitalAccount.getAccountAmount());
            capitalAccountUnstLog.setScore(capitalAccount.getScore());
            capitalAccountUnstLog.setDeposit((int) capitalAccount.getDeposit());
            capitalAccountUnstLog.setDepositFreeze((int) capitalAccount.getDepositFreeze());
            capitalAccountUnstLog.setWithdraw((int) capitalAccount.getWithdraw());
            capitalAccountUnstLog.setWithdrawFreeze((int) capitalAccount.getWithdrawFreeze());

            int accountLogaddResult = serveService.capitalAccountLogadd(capitalAccountUnstLog);
            if (accountLogaddResult == 0) {
                LOGGER.info("OrderSplittingServiceImpl:splitSettled, capitalAccountLogadd failed, payId:{}, capitalAccountUnstLog:{}", payId, capitalAccountUnstLog);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }
        }
    }

    /**
     * 骑手待结算
     *
     * @param payId
     * @param thirdpartId
     * @param amount
     */
    @Transactional
    public void riderSplitting(String payId, String thirdpartId, int amount) {
        //系统账户支出
        CapitalAccount systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        //判断 资金账户不能未null
        if (systemAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:riderSplitting, systemAccount is null, payId:{}, thirdpartId{}, amount:{}", payId, 5, amount);
            return;
        }
        //系统账户分账开始---------------------------------------------
        //系统账户出金-骑手返佣待结算扣减
        int systemAccount = serveService.updatedepositfreezesub(amount, systemAccountInfo.getId());
        if (systemAccount == 0) {
            LOGGER.info("OrderSplittingServiceImpl:riderSplitting, systemAccount updatedepositfreezesub failed, payId:{}, thirdpartId:{}, amount:{}, systemAccountInfo:{}",
                    payId, 5, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //系统账户出金-骑手返佣待结算记录增加
        systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        int splittingIn = instertAccountUnstlog(systemAccountInfo.getId(), "out", "骑手分佣:" + payId, payId, amount,
                BusinessType.rider_commission, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (splittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:riderSplitting, systemAccount instertAccountUnstlog failed, payId:{}, thirdpartId:{}, amount:{}, systemAccountInfo:{}, ",
                    payId, 5, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }

        //查询骑手资金账户信息
        CapitalAccount riderAccountInfo = serveService.capitalAccountInfo(thirdpartId, "2");
        //判断 资金账户不能未null
        if (riderAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:riderSplitting, riderAccountInfo is null, payId:{}, thirdpartId{}, amount:{}", payId, thirdpartId, amount);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //骑手账户待结算增加返佣金额
        int riderAccount = serveService.updatedepositfreezeadd(amount, riderAccountInfo.getId());
        if (riderAccount == 0) {
            LOGGER.info("OrderSplittingServiceImpl:riderSplitting, riderAccountInfo updatedepositfreezeadd failed, payId:{}, thirdpartId{}, amount:{}, riderAccountInfo:{}", payId, thirdpartId, amount, riderAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //骑手账户待结算增加日志
        riderAccountInfo = serveService.capitalAccountInfo(thirdpartId, "2");
        int riderSplittingIn = instertAccountUnstlog(riderAccountInfo.getId(), "in", "骑手分佣:" + payId, payId, amount,
                BusinessType.rider_commission, (int) riderAccountInfo.getDeposit(), (int) riderAccountInfo.getDepositFreeze(),
                (int) riderAccountInfo.getWithdraw(), (int) riderAccountInfo.getWithdrawFreeze(),
                riderAccountInfo.getScore(), (int) riderAccountInfo.getAccountAmount());
        if (riderSplittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:riderSplitting, riderAccountInfo instertAccountUnstlog failed, payId:{}, thirdpartId{}, amount:{}, riderAccountInfo:{}", payId, thirdpartId, amount, riderAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //骑手账户分账结束---------------------------------------------
    }

    /**
     * 资金业务处理 订单分账；根据订单号查出分账记录，按各角色进行分账，把待结算划转到可提现
     *
     * @param relatedNo 提现单号
     */
    @Transactional
    public void withdrawal(String relatedNo) {
        //根据订单号查询待结算的列表
        List<CapitalAccountUnstLog> capitalAccountUnstLogList = serveService.findByCapitalAccountUnstLogList(relatedNo);
        for (CapitalAccountUnstLog capitalAccountUnstLog : capitalAccountUnstLogList) {
            //更新已结算
            CapitalAccount capitalAccount = serveService.capitalAccountInfoForUpdate(capitalAccountUnstLog.getAccountId());
            if (capitalAccount == null) {
                LOGGER.info("OrderSplittingServiceImpl:splitSettled, capitalAccount is null, payId:{}, capitalAccountUnstLog:{}", relatedNo, capitalAccountUnstLog);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }

            if ("in".equals(capitalAccountUnstLog.getType())) {
                int updateDepositAddResult = serveService.updateDepositAdd(capitalAccountUnstLog.getAmount(), capitalAccountUnstLog.getAccountId());
                if (updateDepositAddResult == 0) {
                    LOGGER.info("OrderSplittingServiceImpl:splitSettled, updateDepositAdd failed, payId:{}, capitalAccountUnstLog:{}", relatedNo, capitalAccountUnstLog);
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return;
                }
                int updatedepositfreezesubResult = serveService.updatedepositfreezesub(capitalAccountUnstLog.getAmount(), capitalAccountUnstLog.getAccountId());
                if (updatedepositfreezesubResult == 0) {
                    LOGGER.info("OrderSplittingServiceImpl:splitSettled, updatedepositfreezesub failed, payId:{}, capitalAccountUnstLog:{}", relatedNo, capitalAccountUnstLog);
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return;
                }
            } else if ("out".equals(capitalAccountUnstLog.getType())) {
                int updateDepositSubResult = serveService.updateDepositSub(capitalAccountUnstLog.getAmount(), capitalAccountUnstLog.getAccountId());
                if (updateDepositSubResult == 0) {
                    LOGGER.info("OrderSplittingServiceImpl:splitSettled, updateDepositSub failed, payId:{}, capitalAccountUnstLog:{}", relatedNo, capitalAccountUnstLog);
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return;
                }
                int updatedepositfreezeaddResult = serveService.updatedepositfreezeadd(capitalAccountUnstLog.getAmount(), capitalAccountUnstLog.getAccountId());
                if (updatedepositfreezeaddResult == 0) {
                    LOGGER.info("OrderSplittingServiceImpl:splitSettled, updatedepositfreezeadd failed, payId:{}, capitalAccountUnstLog:{}", relatedNo, capitalAccountUnstLog);
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return;
                }
            }
            //更新已结算的标识
            int updateIsSettResult = serveService.updateIsSett(relatedNo, capitalAccountUnstLog.getId());
            if (updateIsSettResult == 0) {
                LOGGER.info("OrderSplittingServiceImpl:splitSettled, updateIsSett failed, payId:{}, capitalAccountUnstLog:{}", relatedNo, capitalAccountUnstLog);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }
            //添加到已结算表
            capitalAccount = serveService.capitalAccountInfoForUpdate(capitalAccountUnstLog.getAccountId());
            capitalAccountUnstLog.setAccountAmount((int) capitalAccount.getAccountAmount());
            capitalAccountUnstLog.setScore(capitalAccount.getScore());
            capitalAccountUnstLog.setDeposit((int) capitalAccount.getDeposit());
            capitalAccountUnstLog.setDepositFreeze((int) capitalAccount.getDepositFreeze());
            capitalAccountUnstLog.setWithdraw((int) capitalAccount.getWithdraw());
            capitalAccountUnstLog.setWithdrawFreeze((int) capitalAccount.getWithdrawFreeze());

            int accountLogaddResult = serveService.capitalAccountLogadd(capitalAccountUnstLog);
            if (accountLogaddResult == 0) {
                LOGGER.info("OrderSplittingServiceImpl:splitSettled, capitalAccountLogadd failed, payId:{}, capitalAccountUnstLog:{}", relatedNo, capitalAccountUnstLog);
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return;
            }
        }
    }

    /**
     * 资金业务处理 邀请奖励结算
     *
     * @param userId        邀请人用户id
     * @param userType      用户类型
     * @param inviteeUserId 被邀请人用户id
     * @param amount        奖励金额
     */
    public void invitationRewardsSettl(String userId, String userType, String inviteeUserId, int amount) {

        //查询系统账户的资金信息
        CapitalAccount systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        //判断 资金账户不能未null
        if (systemAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, systemAccount is null, userId:{}, amount:{}", userId, amount);
            return;
        }

        //1 系统账户已结算扣除奖励金额
        int updateDepositAddResult = serveService.updateDepositSub(amount, systemAccountInfo.getId());
        if (updateDepositAddResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:splitSettled, updateDepositSub failed, userId:{}, amount:{}, systemAccountInfo:{}", userId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //2 系统账户已结算扣除奖励金额 add Log
        systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        int splittingOut = instertAccountLog(systemAccountInfo.getId(), "out", "邀请奖励:被邀请人-" + inviteeUserId, userId + ":" + inviteeUserId, amount,
                BusinessType.invitation_rewards, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (splittingOut == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, systemAccount invitation_rewards instertAccountLog failed, userId:{}, amount:{}, systemAccountInfo:{}", userId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }

        //3 邀请账户已结算增加奖励金额
        CapitalAccount userAccountInfo = serveService.capitalAccountInfo(userId, userType);
        //判断 资金账户不能未null
        if (userAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, userAccountInfo is null, userId:{}, amount:{}, systemAccountInfo:{}", userId, amount, systemAccountInfo);
            return;
        }
        int userAccountInfoResult = serveService.updateDepositAdd(amount, userAccountInfo.getId());
        if (userAccountInfoResult == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, userAccountInfo updateDepositAdd failed, userId:{}, amount:{}, systemAccountInfo:{}, userAccountInfo:{}", userId, amount, systemAccountInfo, userAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
        //4 邀请账户已结算增加奖励金额 add Log
        userAccountInfo = serveService.capitalAccountInfo(userId, userType);
        int splittingIn = instertAccountLog(userAccountInfo.getId(), "in", "邀请奖励:被邀请人-" + inviteeUserId, userId + ":" + inviteeUserId, amount,
                BusinessType.invitation_rewards, (int) userAccountInfo.getDeposit(), (int) userAccountInfo.getDepositFreeze(),
                (int) userAccountInfo.getWithdraw(), (int) userAccountInfo.getWithdrawFreeze(),
                userAccountInfo.getScore(), (int) userAccountInfo.getAccountAmount());
        if (splittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:OrderUserRecharge, userAccount invitation_rewards instertAccountLog failed, userId:{}, amount:{}, systemAccountInfo:{}", userId, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return;
        }
    }

    /**
     * 司机分佣
     * @param userId
     * @param subOrderId
     * @param amount
     * @return
     */
    @Transactional
    public int driverAccounting(String userId,String subOrderId,int amount){
        //系统账户支出
        CapitalAccount systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        //判断 资金账户不能未null
        if (systemAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:driverAccounting, systemAccount is null, userId:{}, subOrderId{}, amount:{}", userId, subOrderId, amount);
            return 0;
        }
        //系统账户分账开始---------------------------------------------
        //系统账户出金-司机返佣待结算扣减
        int systemAccount = serveService.updatedepositfreezesub(amount, systemAccountInfo.getId());
        if (systemAccount == 0) {
            LOGGER.info("OrderSplittingServiceImpl:driverAccounting, systemAccount updatedepositfreezesub failed, subOrderId:{}, thirdpartId:{}, amount:{}, systemAccountInfo:{}",
                    subOrderId, 5, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
        //系统账户出金-司机返佣待结算记录增加
        systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        int splittingIn = instertAccountUnstlog(systemAccountInfo.getId(), "out", "司机分佣:" + subOrderId, subOrderId, amount,
                BusinessType.driver_commission, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (splittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:driverAccounting, systemAccount instertAccountUnstlog failed, subOrderId:{}, thirdpartId:{}, amount:{}, systemAccountInfo:{}, ",
                    subOrderId, 5, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }

        //查询司机资金账户信息
        CapitalAccount riderAccountInfo = serveService.capitalAccountInfo(userId, "2");
        //判断 资金账户不能未null
        if (riderAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:driverAccounting, riderAccountInfo is null, subOrderId:{}, thirdpartId{}, amount:{}", subOrderId, userId, amount);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
        //司机账户待结算增加返佣金额
        int riderAccount = serveService.updatedepositfreezeadd(amount, riderAccountInfo.getId());
        if (riderAccount == 0) {
            LOGGER.info("OrderSplittingServiceImpl:driverAccounting, riderAccountInfo updatedepositfreezeadd failed, subOrderId:{}, thirdpartId{}, amount:{}, driverAccountInfo:{}", subOrderId, userId, amount, riderAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
        //司机账户待结算增加日志
        riderAccountInfo = serveService.capitalAccountInfo(userId, "2");
        int riderSplittingIn = instertAccountUnstlog(riderAccountInfo.getId(), "in", "司机分佣:" + subOrderId, subOrderId, amount,
                BusinessType.driver_commission, (int) riderAccountInfo.getDeposit(), (int) riderAccountInfo.getDepositFreeze(),
                (int) riderAccountInfo.getWithdraw(), (int) riderAccountInfo.getWithdrawFreeze(),
                riderAccountInfo.getScore(), (int) riderAccountInfo.getAccountAmount());
        if (riderSplittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:driverAccounting, riderAccountInfo instertAccountUnstlog failed, subOrderId:{}, thirdpartId{}, amount:{}, driverAccountInfo:{}", subOrderId, userId, amount, riderAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
        //司机账户分账结束---------------------------------------------
        return 1;
    }

    /**
     * 小站分佣
     * @param shopsId
     * @param orderId
     * @param amount
     * @return
     */
    public int siteCommission(String shopsId, String orderId,int amount,String subOrderId){
        //系统账户支出
        CapitalAccount systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        //判断 资金账户不能未null
        if (systemAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:siteCommission, systemAccount is null, orderId:{}, thirdpartId{}, amount:{}", orderId, 5, amount);
            return 0;
        }
        //系统账户分账开始---------------------------------------------
        //系统账户出金-小站返佣待结算扣减
        int systemAccount = serveService.updatedepositfreezesub(amount, systemAccountInfo.getId());
        if (systemAccount == 0) {
            LOGGER.info("OrderSplittingServiceImpl:siteCommission, systemAccount updatedepositfreezesub failed, orderId:{}, thirdpartId:{}, amount:{}, systemAccountInfo:{}",
                    orderId, 5, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
        //系统账户出金-小站返佣待结算记录增加
        systemAccountInfo = serveService.capitalAccountInfo("jsb", "5");
        int splittingIn = instertAccountUnstlog(systemAccountInfo.getId(), "out", "小站分佣:" + subOrderId, orderId, amount,
                BusinessType.shops_commission, (int) systemAccountInfo.getDeposit(), (int) systemAccountInfo.getDepositFreeze(),
                (int) systemAccountInfo.getWithdraw(), (int) systemAccountInfo.getWithdrawFreeze(),
                systemAccountInfo.getScore(), (int) systemAccountInfo.getAccountAmount());
        if (splittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:siteCommission, systemAccount instertAccountUnstlog failed, orderId:{}, thirdpartId:{}, amount:{}, systemAccountInfo:{}, ",
                    orderId, 5, amount, systemAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }

        //查询小站资金账户信息
        CapitalAccount shopAccountInfo = serveService.capitalAccountInfo(shopsId, "3");
        //判断 资金账户不能未null
        if (shopAccountInfo == null) {
            LOGGER.info("OrderSplittingServiceImpl:siteCommission, shopAccountInfo is null, orderId:{}, thirdpartId{}, amount:{}", orderId, shopsId, amount);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
        //小站账户待结算增加返佣金额
        int shopAccount = serveService.updatedepositfreezeadd(amount, shopAccountInfo.getId());
        if (shopAccount == 0) {
            LOGGER.info("OrderSplittingServiceImpl:siteCommission, shopAccount updatedepositfreezeadd failed, orderId:{}, thirdpartId{}, amount:{}, shopsAccountInfo:{}", orderId, shopsId, amount, shopAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
        //小站账户待结算增加日志
        shopAccountInfo = serveService.capitalAccountInfo(shopsId, "3");
        int shopSplittingIn = instertAccountUnstlog(shopAccountInfo.getId(), "in", "小站分佣:" + subOrderId, orderId, amount,
                BusinessType.shops_commission, (int) shopAccountInfo.getDeposit(), (int) shopAccountInfo.getDepositFreeze(),
                (int) shopAccountInfo.getWithdraw(), (int) shopAccountInfo.getWithdrawFreeze(),
                shopAccountInfo.getScore(), (int) shopAccountInfo.getAccountAmount());
        if (shopSplittingIn == 0) {
            LOGGER.info("OrderSplittingServiceImpl:siteCommission, shopAccountInfo instertAccountUnstlog failed, orderId:{}, thirdpartId{}, amount:{}, shopsAccountInfo:{}", orderId, shopsId, amount, shopAccountInfo);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
        //小站账户分账结束---------------------------------------------
        return 1;
    }
}
